/**
 * "Visual Paradigm: DO NOT MODIFY THIS FILE!"
 * 
 * This is an automatic generated file. It will be regenerated every time 
 * you generate persistence class.
 * 
 * Modifying its content may cause the program not work, or your work may lost.
 */

/**
 * Licensee: DuKe TeAm
 * License Type: Purchased
 */
package orm.impl;

import org.orm.*;
import org.hibernate.Query;
import java.util.List;
import orm.*;

public class Tbv_ruta_programadaDAOImpl implements orm.dao.Tbv_ruta_programadaDAO {
	public Tbv_ruta_programada loadTbv_ruta_programadaByORMID(int rp_id_ruta_programada) throws PersistentException {
		try {
			PersistentSession session = orm.Bdvendomaticav04PersistentManager.instance().getSession();
			return loadTbv_ruta_programadaByORMID(session, rp_id_ruta_programada);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_ruta_programada getTbv_ruta_programadaByORMID(int rp_id_ruta_programada) throws PersistentException {
		try {
			PersistentSession session = orm.Bdvendomaticav04PersistentManager.instance().getSession();
			return getTbv_ruta_programadaByORMID(session, rp_id_ruta_programada);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_ruta_programada loadTbv_ruta_programadaByORMID(int rp_id_ruta_programada, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.Bdvendomaticav04PersistentManager.instance().getSession();
			return loadTbv_ruta_programadaByORMID(session, rp_id_ruta_programada, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_ruta_programada getTbv_ruta_programadaByORMID(int rp_id_ruta_programada, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.Bdvendomaticav04PersistentManager.instance().getSession();
			return getTbv_ruta_programadaByORMID(session, rp_id_ruta_programada, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_ruta_programada loadTbv_ruta_programadaByORMID(PersistentSession session, int rp_id_ruta_programada) throws PersistentException {
		try {
			return (Tbv_ruta_programada) session.load(orm.Tbv_ruta_programada.class, new Integer(rp_id_ruta_programada));
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_ruta_programada getTbv_ruta_programadaByORMID(PersistentSession session, int rp_id_ruta_programada) throws PersistentException {
		try {
			return (Tbv_ruta_programada) session.get(orm.Tbv_ruta_programada.class, new Integer(rp_id_ruta_programada));
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_ruta_programada loadTbv_ruta_programadaByORMID(PersistentSession session, int rp_id_ruta_programada, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			return (Tbv_ruta_programada) session.load(orm.Tbv_ruta_programada.class, new Integer(rp_id_ruta_programada), lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_ruta_programada getTbv_ruta_programadaByORMID(PersistentSession session, int rp_id_ruta_programada, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			return (Tbv_ruta_programada) session.get(orm.Tbv_ruta_programada.class, new Integer(rp_id_ruta_programada), lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_ruta_programada[] listTbv_ruta_programadaByQuery(String condition, String orderBy) throws PersistentException {
		try {
			PersistentSession session = orm.Bdvendomaticav04PersistentManager.instance().getSession();
			return listTbv_ruta_programadaByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_ruta_programada[] listTbv_ruta_programadaByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.Bdvendomaticav04PersistentManager.instance().getSession();
			return listTbv_ruta_programadaByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_ruta_programada[] listTbv_ruta_programadaByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.Tbv_ruta_programada as Tbv_ruta_programada");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			List list = query.list();
			return (Tbv_ruta_programada[]) list.toArray(new Tbv_ruta_programada[list.size()]);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_ruta_programada[] listTbv_ruta_programadaByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.Tbv_ruta_programada as Tbv_ruta_programada");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			query.setLockMode("this", lockMode);
			List list = query.list();
			return (Tbv_ruta_programada[]) list.toArray(new Tbv_ruta_programada[list.size()]);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_ruta_programada loadTbv_ruta_programadaByQuery(String condition, String orderBy) throws PersistentException {
		try {
			PersistentSession session = orm.Bdvendomaticav04PersistentManager.instance().getSession();
			return loadTbv_ruta_programadaByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_ruta_programada loadTbv_ruta_programadaByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.Bdvendomaticav04PersistentManager.instance().getSession();
			return loadTbv_ruta_programadaByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_ruta_programada loadTbv_ruta_programadaByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException {
		Tbv_ruta_programada[] tbv_ruta_programadas = listTbv_ruta_programadaByQuery(session, condition, orderBy);
		if (tbv_ruta_programadas != null && tbv_ruta_programadas.length > 0)
			return tbv_ruta_programadas[0];
		else
			return null;
	}
	
	public Tbv_ruta_programada loadTbv_ruta_programadaByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		Tbv_ruta_programada[] tbv_ruta_programadas = listTbv_ruta_programadaByQuery(session, condition, orderBy, lockMode);
		if (tbv_ruta_programadas != null && tbv_ruta_programadas.length > 0)
			return tbv_ruta_programadas[0];
		else
			return null;
	}
	
	public static java.util.Iterator iterateTbv_ruta_programadaByQuery(String condition, String orderBy) throws PersistentException {
		try {
			PersistentSession session = orm.Bdvendomaticav04PersistentManager.instance().getSession();
			return iterateTbv_ruta_programadaByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static java.util.Iterator iterateTbv_ruta_programadaByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.Bdvendomaticav04PersistentManager.instance().getSession();
			return iterateTbv_ruta_programadaByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static java.util.Iterator iterateTbv_ruta_programadaByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.Tbv_ruta_programada as Tbv_ruta_programada");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			return query.iterate();
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static java.util.Iterator iterateTbv_ruta_programadaByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.Tbv_ruta_programada as Tbv_ruta_programada");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			query.setLockMode("this", lockMode);
			return query.iterate();
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_ruta_programada createTbv_ruta_programada() {
		return new orm.Tbv_ruta_programada();
	}
	
	public boolean save(orm.Tbv_ruta_programada tbv_ruta_programada) throws PersistentException {
		try {
			orm.Bdvendomaticav04PersistentManager.instance().saveObject(tbv_ruta_programada);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean delete(orm.Tbv_ruta_programada tbv_ruta_programada) throws PersistentException {
		try {
			orm.Bdvendomaticav04PersistentManager.instance().deleteObject(tbv_ruta_programada);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean deleteAndDissociate(orm.Tbv_ruta_programada tbv_ruta_programada)throws PersistentException {
		try {
			if(tbv_ruta_programada.getTbv_rutaru_id_ruta() != null) {
				tbv_ruta_programada.getTbv_rutaru_id_ruta().tbv_ruta_programada.remove(tbv_ruta_programada);
			}
			
			orm.Tbv_bitacora_ruta[] lTbv_bitacora_rutas = tbv_ruta_programada.tbv_bitacora_ruta.toArray();
			for(int i = 0; i < lTbv_bitacora_rutas.length; i++) {
				lTbv_bitacora_rutas[i].setTbv_ruta_programadarp_id_ruta_programada(null);
			}
			orm.Tbv_maquina_tbv_ruta_programada[] lTbv_maquina_tbv_ruta_programadas = tbv_ruta_programada.tbv_maquina_tbv_ruta_programada.toArray();
			for(int i = 0; i < lTbv_maquina_tbv_ruta_programadas.length; i++) {
				lTbv_maquina_tbv_ruta_programadas[i].setTbv_ruta_programadarp_id_ruta_programada(null);
			}
			return delete(tbv_ruta_programada);
		}
		catch(Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean deleteAndDissociate(orm.Tbv_ruta_programada tbv_ruta_programada, org.orm.PersistentSession session)throws PersistentException {
		try {
			if(tbv_ruta_programada.getTbv_rutaru_id_ruta() != null) {
				tbv_ruta_programada.getTbv_rutaru_id_ruta().tbv_ruta_programada.remove(tbv_ruta_programada);
			}
			
			orm.Tbv_bitacora_ruta[] lTbv_bitacora_rutas = tbv_ruta_programada.tbv_bitacora_ruta.toArray();
			for(int i = 0; i < lTbv_bitacora_rutas.length; i++) {
				lTbv_bitacora_rutas[i].setTbv_ruta_programadarp_id_ruta_programada(null);
			}
			orm.Tbv_maquina_tbv_ruta_programada[] lTbv_maquina_tbv_ruta_programadas = tbv_ruta_programada.tbv_maquina_tbv_ruta_programada.toArray();
			for(int i = 0; i < lTbv_maquina_tbv_ruta_programadas.length; i++) {
				lTbv_maquina_tbv_ruta_programadas[i].setTbv_ruta_programadarp_id_ruta_programada(null);
			}
			try {
				session.delete(tbv_ruta_programada);
				return true;
			} catch (Exception e) {
				return false;
			}
		}
		catch(Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean refresh(orm.Tbv_ruta_programada tbv_ruta_programada) throws PersistentException {
		try {
			orm.Bdvendomaticav04PersistentManager.instance().getSession().refresh(tbv_ruta_programada);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean evict(orm.Tbv_ruta_programada tbv_ruta_programada) throws PersistentException {
		try {
			orm.Bdvendomaticav04PersistentManager.instance().getSession().evict(tbv_ruta_programada);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_ruta_programada loadTbv_ruta_programadaByCriteria(Tbv_ruta_programadaCriteria tbv_ruta_programadaCriteria) {
		Tbv_ruta_programada[] tbv_ruta_programadas = listTbv_ruta_programadaByCriteria(tbv_ruta_programadaCriteria);
		if(tbv_ruta_programadas == null || tbv_ruta_programadas.length == 0) {
			return null;
		}
		return tbv_ruta_programadas[0];
	}
	
	public Tbv_ruta_programada[] listTbv_ruta_programadaByCriteria(Tbv_ruta_programadaCriteria tbv_ruta_programadaCriteria) {
		return tbv_ruta_programadaCriteria.listTbv_ruta_programada();
	}
}
